
from datetime import datetime
from django.db import models

from TenSquare.utils.BaseModel import BaseModel
from users.models import User


# 吐槽和吐槽的评论数据都存储在mongodb中,不是存储在mysql中
# 吐槽和吐槽的评论都属于吐槽的这张表
# 吐槽的parent_id为None,评论则有parent_id
class Spit(BaseModel):
    content = models.CharField(max_length=200)  # 吐槽内容
    publishtime = models.DateTimeField(default=datetime.utcnow, verbose_name='发布日期')  # 发布日期
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="发布人", null=True)  # 发布人ID
    nickname = models.CharField(max_length=100, null=True, verbose_name='发布人昵称')  # 发布人昵称
    visits = models.IntegerField(default=0, verbose_name='阅览量')  # 浏览量
    thumbup = models.IntegerField(default=0, verbose_name='点赞数')  # 点赞数
    comment = models.IntegerField(default=0, verbose_name='回复数')  # 回复数
    avatar = models.ImageField(verbose_name='用户头像')  # 用户的头像
    parent = models.ForeignKey('self', null=True,
                               on_delete=models.SET_NULL,
                               verbose_name='上级id')  # 上级ID
    collected = models.BooleanField(default=False, verbose_name='是否收藏')  # 是否收藏
    hasthumbup = models.BooleanField(default=False, verbose_name='是否点赞')  # 是否点赞
